package com.simou.common;

import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.HashMap;

@Component
// 返回结果类
public class R<T> implements Serializable {
    private long code;
    private Object data;
    private String msg;
    private HashMap<String,Object> resultMap;

    // 成功
    public static <T> R<T> success(Object object){
        R<T> r = new R<T>();
        r.code = 1L;
        r.data = object;
        r.msg = "成功";
        return r;
    }

    // 失败
    public static <T> R<T> error(String msg){
        R r = new R();
        r.code = 0;
        r.msg = msg;
        return r;
    }

    // 自定义返回的map
    public R<T> add(String key, Object object){
        this.resultMap.put(key,object);
        return this;
    }

    public long getCode() {
        return code;
    }

    public void setCode(long code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public HashMap<String, Object> getResultMap() {
        return resultMap;
    }

    public void setResultMap(HashMap<String, Object> resultMap) {
        this.resultMap = resultMap;
    }
}
